﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LeMigue.TeamPortal.Base.Biz.Interface;
using LeMigue.TeamPortal.Base.View;
using LeMigue.Scrum.Iterface.Model;
using LeMigue.TeamPortal.Base.Biz;
using System.Web;
using LeMigue.Framework.Utils;

namespace LeMigue.TeamPortal.Dev.Biz
{
    public class DevTeamBiz : ITeamBiz
    {
        private IDictionary<int, Team> _teams = new Dictionary<int, Team>();

        public DevTeamBiz()
        {
            _teams.Add(1, new Team(1, "Team Teste Dev"));
        }

        public IList<TeamView> List(Team ativo)
        {
            return _teams.Values.Select(t => new TeamView(t, ativo != null && t.Id == ativo.Id)).ToList();
        }

        public Team Load(int? id)
        {
            if (!id.HasValue)
            {
                return null;
            }

            User usuario = FactoryBiz.CurrentUser.GetUser(HttpContext.Current);

            Team team = Cache.Get<Team>(usuario.Ref, "Team");

            if (team != null && team.Id == id)
                return team;

            Cache.Remove(usuario.Ref, "Team");

            team = _teams[id.Value];

            Cache.Set<Team>(usuario.Ref, "Team", team);

            return team;

        }

        public TeamView TeamView(Team team, bool ativo)
        {
            return new TeamView(team, ativo);
        }
    }
}
